FROM centos:7

# set environment
ENV MODE="cluster" \
    PREFER_HOST_MODE="ip"\
    BASE_DIR="/home/nacos" \
    CLASSPATH=".:/home/nacos/conf:$CLASSPATH" \
    CLUSTER_CONF="/home/nacos/conf/cluster.conf" \
    FUNCTION_MODE="all" \
    JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk" \
    MAVEM_HOME="/usr/local/maven" \
    NACOS_USER="nacos" \
    JAVA="/usr/lib/jvm/java-1.8.0-openjdk/bin/java" \
    JVM_XMS="1g" \
    JVM_XMX="1g" \
    JVM_XMN="512m" \
    JVM_MS="128m" \
    JVM_MMS="320m" \
    NACOS_DEBUG="n" \
    TOMCAT_ACCESSLOG_ENABLED="false" \
    TIME_ZONE="Asia/Shanghai"

ARG NACOS_VERSION=2.0.3
ARG HOT_FIX_FLAG=""



#安装jdk
RUN set -x \
    && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
    && yum clean all && yum makecache \
    && yum update -y \
    && yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel wget iputils nc  vim libcurl dos2unix

COPY version/${NACOS_VERSION}/${NACOS_VERSION}.tar.gz /home/
COPY version/apache-maven-3.8.4-bin.tar.gz /home/

#配置maven
RUN tar -xzvf /home/apache-maven-3.8.4-bin.tar.gz -C /home \
    && mv /home/apache-maven-3.8.4 /usr/local/bin \
    && export PATH=apache-maven-3.8.4/bin:$PATH \
    && export PATH=/usr/local/bin/apache-maven-3.8.4/bin:$PATH \
    && ln -s /usr/local/bin/apache-maven-3.8.4/bin/mvn /usr/local/bin/mvn \
    && echo $PATH && rm -rf /home/apache-maven-3.8.4-bin.tar.gz


RUN tar -xzvf /home/${NACOS_VERSION}.tar.gz -C /home  \
    && rm -rf /home/${NACOS_VERSION}.tar.gz

COPY config/conf/settings.xml /root/.m2/settings.xml



RUN  cd /home/nacos-${NACOS_VERSION}  && mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U \
     && cp -R /home/nacos-${NACOS_VERSION}/distribution/target/nacos-server-${NACOS_VERSION}/nacos /home/nacos

WORKDIR $BASE_DIR

RUN rm -rf /home/nacos/bin/* /home/nacos/conf/*.properties \
 /home/nacos/conf/*.example /home/nacos/conf/nacos-mysql.sql


RUN yum autoremove -y wget \
    && ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone \
    && yum clean all

ADD config/bin/docker-startup.sh bin/docker-startup.sh
ADD config/conf/application.properties conf/application.properties

# set startup log dir
RUN mkdir -p logs \
	&& cd logs \
	&& touch start.out \
	&& ln -sf /dev/stdout start.out \
	&& ln -sf /dev/stderr start.out
RUN dos2unix bin/docker-startup.sh && chmod +x bin/docker-startup.sh

EXPOSE 8848
ENTRYPOINT ["bin/docker-startup.sh"]